#ifndef __PRJINFO_H__
#define __PRJINFO_H__

#include <stdint.h>

/* 固件信息结构体定义 */
typedef struct __attribute__((packed)) project_info
{
    char name[16];       /* 项目名称 */
    char ver_major;      /* 主版本号 */
    char ver_minor;      /* 次版本号 */
    char ver_revision;   /* 修订版号 */
    char padding[9];     /* 项目名称 */
    uint32_t swver;      /* 软件日期 */
    char build_date[16]; /* 编译日期 */
    char build_time[16]; /* 编译时间 */
    /* todo : other info */
} project_info_t;

/* 声明指定存储地址 */
#define PROJECT_INFO_ADDR 0x08000400U

#define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
+ (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))  

/**
January (Jan)---Febuary (Feb)---March (Mar)---April (Apr)---May (May)---June (Jun)--
July (Jul)---August (Aug)---September (Sep)---October (Oct)---November (Nov)---SDecember (Dec)--
*/
 
#define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [0] == 'J' ? 1 : 6) \
: __DATE__ [2] == 'b' ? 2 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
: __DATE__ [2] == 'y' ? 5 \
: __DATE__ [2] == 'l' ? 7 \
: __DATE__ [2] == 'g' ? 8 \
: __DATE__ [2] == 'p' ? 9 \
: __DATE__ [2] == 't' ? 10 \
: __DATE__ [2] == 'v' ? 11 : 12)  
  
#define DAY     ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 + (__DATE__ [5] - '0'))
#define HOUR    ((__TIME__ [0] == ' ' ? 0 : __TIME__ [0] - '0') * 10 + (__TIME__ [1] - '0'))
#define MINUTE  ((__TIME__ [3] == ' ' ? 0 : __TIME__ [3] - '0') * 10 + (__TIME__ [4] - '0'))
#define SECOND  ((__TIME__ [6] == ' ' ? 0 : __TIME__ [6] - '0') * 10 + (__TIME__ [7] - '0'))
#define DATE_AS_INT ((YEAR - 2000) * 512 + MONTH * 32 + DAY)
#define VER_AS_INT(m,s,r) ((m) * 65536 + (s) * 256 + (r))
#define VER_GENERATE(y,m,d)		((uint16_t)( ( ((y)&0x7F)<<9 )|( ((m)&0xF)<<5 )|( ((d)&0x1F)<<0 ) ))
#define VER_GET(x)		( ((x)&0x7E00)>>9 ),( ((x)&0x1E0)>>5 ),( ((x)&0x1F)>>0 ) 

project_info_t* PrjInfoGet(uint32_t firmwareaddr);

#endif
